﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PasswordProvider.ViewModel.Helpers
{
    internal static class UriHelper
    {
        public static Uri CreateUri(string url)
        {
            return CreateUri(url, null);
        }

        public static Uri CreateUri(string url, string relativeTo)
        {
            if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                return new Uri(url, UriKind.RelativeOrAbsolute);

            if (relativeTo != null)
            {
                string uri = relativeTo + url;
                if (Uri.IsWellFormedUriString(uri, UriKind.Absolute))
                    return new Uri(uri);
            }
            else
            {
                string temp = "http://" + url;
                if (Uri.IsWellFormedUriString(temp, UriKind.Absolute))
                    return new Uri(temp);
            }

            return null;
        }
    }
}
